<?php
//路由

namespace app\admin\controller;

use app\admin\model\Route as RouteM;

class Route extends Base
{
    protected $middleware = ['app\admin\middleware\UpdateCacheAfter::class']; //缓存控制器中间件
    /**
     * Desc:
     * User: 苏鹏
     * Date: 2023/8/29
     * Time: 20:23
     * @return void
     */
    public function filter(&$map, &$field)
    {
        $parent_id = input('parent_id', 0, 'intval');
        $field = 'id,title,route,rule,method,vue_route';
        $map = [
            'status', 'in', '1,2',
        ];

        if(!empty($parent_id)){
            $map[] = ['pid', '=', $parent_id];
        }

    }

    public function beforeDetail(&$field)
    {
        $field = 'id,title,route,rule,method,vue_route';
    }

    /**
     * Desc: 树结构列表 （全部数据）
     * User: 苏鹏
     * Date: 2023/9/21
     * Time: 9:30
     * @return void
     */
    public function tree()
    {
        try{
            $result = (new RouteM())->getRouteTreeLists();
        }catch (\Exception $e){
            return re_error_json($e->getMessage($this->userId));
        }
        return re_success_json($result);
    }


}